package com.base.data.elasticsearch.core.query.simplify;


import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

public class SearchQuery<T> extends BaseQueryInfo<T> {
    Class<T> clazz;
    BoolQueryBuilder boolQueryBuilder;
    Pageable pageable;
    String[] include;
    String[] exclude;
    AggregationBuilder[] aggregation;
    int size;

    public SearchQuery(SearchQuery.Builder builder) {
        super(builder);
        this.clazz = builder.clazz;
        this.boolQueryBuilder = builder.boolQueryBuilder;
        this.pageable = builder.pageable;
        this.include = builder.include;
        this.exclude = builder.exclude;
        this.aggregation = builder.aggregation;
        this.size = builder.size;
    }

    public Class<T> getClazz() {
        return this.clazz;
    }

    public BoolQueryBuilder getBoolQueryBuilder() {
        return this.boolQueryBuilder;
    }

    public Pageable getPageable() {
        return this.pageable;
    }

    public String[] getInclude() {
        return this.include;
    }

    public String[] getExclude() {
        return this.exclude;
    }

    public AggregationBuilder[] getAggregation() {
        return this.aggregation;
    }

    public int getSize() {
        return this.size;
    }

    public static SearchQuery.Builder builder() {
        return new SearchQuery.Builder();
    }

    public static class Builder<T> extends BaseQueryInfo.Builder {
        private Class<T> clazz;
        private BoolQueryBuilder boolQueryBuilder;
        private Pageable pageable = PageRequest.of(0, 10);
        private String[] include;
        private String[] exclude;
        private AggregationBuilder[] aggregation;
        private int size = 10;

        public Builder() {
        }

        public SearchQuery.Builder clazz(Class<T> clazz) {
            this.clazz = clazz;
            return this;
        }

        public SearchQuery.Builder boolQueryBuilder(BoolQueryBuilder boolQueryBuilder) {
            this.boolQueryBuilder = boolQueryBuilder;
            return this;
        }

        public SearchQuery.Builder pageable(Pageable pageable) {
            this.pageable = pageable;
            return this;
        }

        public SearchQuery.Builder include(String[] include) {
            this.include = include;
            return this;
        }

        public SearchQuery.Builder exclude(String[] exclude) {
            this.exclude = exclude;
            return this;
        }

        public SearchQuery.Builder aggregation(AggregationBuilder... aggregation) {
            this.aggregation = aggregation;
            return this;
        }

        public SearchQuery.Builder size(int size) {
            this.size = size;
            return this;
        }

        public SearchQuery.Builder index(String index) {
            super.index = index;
            return this;
        }

        public SearchQuery.Builder type(String type) {
            super.type = type;
            return this;
        }

        public SearchQuery<T> build() {
            return new SearchQuery(this);
        }
    }
}
